package com.wngbms.feigndemo.aop;

import java.lang.reflect.Proxy;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class ClassLoadingDemo {

    public static void main(String[] args) throws InterruptedException {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        System.out.println(contextClassLoader);
//        TimeUnit.SECONDS.sleep(13);

        System.setProperty("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
        System.setProperty("jdk.proxy.ProxyGenerator.saveGeneratedFiles", "true");

        for (int i = 0; i < 100; i++) {
            ProxyRunnable proxyRunnable = new ProxyRunnable(UUID.randomUUID().toString(), new Runnable() {
                @Override
                public void run() {
                    System.out.println(this.hashCode());
                }
            });
            Runnable pr = (Runnable) Proxy.newProxyInstance(contextClassLoader, new Class[]{Runnable.class}, proxyRunnable);
            System.out.println(pr.getClass().getSimpleName() + "\t" + pr.getClass().hashCode());
//            System.out.println();
            pr.run();
        }
    }

}
